﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<link rel="stylesheet" type="text/css" media="screen" href="css/jquery-ui-1.8.1.custom.css" />
<link rel="stylesheet" type="text/css" media="screen" href="css/ui.jqgrid.css" />
<script src="js/jquery-1.5.2.min.js" type="text/javascript"></script>
<script src="js/i18n/grid.locale-cn.js" type="text/javascript"></script>
<script src="js/json2.js" type="text/javascript"></script>
<script src="js/xing.js" type="text/javascript"></script>
<script type="text/javascript">
	$.jgrid.no_legacy_api = true;
	$.jgrid.useJSON = true;
</script>
<script src="js/jquery.jqGrid.min.js" type="text/javascript"></script>
<script type="text/javascript">
var myStreets = [];
var udistrict, usid;

function checkValue(postdata, formid) {
	/*
	var uid = +(postdata.uid);
	if (uid < 10) {
		if (postdata.sid != "0")
			return [false,"对于局工作人员，不能填入街道名称"];
	}
	if (uid > 10) {
		if (postdata.sid == "0")
			return [false,"对于街道办事处，必须要填入街道名称"];
	}
	*/
	return [true,""];
};

function checkValueForDel(postdata, formid) {
	var uid = +(postdata);
	if (uid <= 10) {
		return [false,"对于市残联和县区残联工作人员，不允许删除，只能更改！"];
	}
	return [true,""];
};

function initStreet() {
	$.ajax({url:'base?action=13',async:false,success: function (data, textStatus) {
			$.extend(true, myStreets, data.streets);
			myStreets.push({"sid":"0","sname":"市残联用户"});
			//udistrict = data.udistrict;
	}});
};

function setStreet(cellvalue, options, rowObject) {
  var sid = rowObject[4];
	for (var j=0; j < myStreets.length; j++) {
     if (myStreets[j].sid == sid) {
       return myStreets[j].sname;
     }
  }
};

function setButton() {
		if (usid != "0")
			return;
		
		jQuery("#list1").jqGrid('navGrid','#gridpager1',{edit:false,add:false,del:false,refresh:false,search:false})
		.jqGrid('navButtonAdd','#gridpager1',{
   		caption:"添加", 
   		buttonicon:"ui-icon-plus", 
   		onClickButton: function(){
				jQuery("#list1").jqGrid('editGridRow','new',{
					addCaption:"添加一个乡镇街道工作人员",
					bSubmit:"保存",bCancel:"取消",modal: true, 
					closeAfterAdd:true, 
					reloadAfterSubmit:true,
					beforeSubmit:checkValue,
					afterSubmit : function(r, postdata) {
			  					var data = eval('(' + r.responseText + ')');
			  					switch (data.code) {
			  						case 0: return [true, data.message]; break;
			  						case 30000: return [false, "添加失败，用户ID不能重复！"]; break;
			  						default: return [false, data.message];
			  					}
			  	}
			  }); 
			}
		})
		.jqGrid('navButtonAdd','#gridpager1',{
   		caption:"更改", 
   		buttonicon:"ui-icon-wrench", 
   		onClickButton: function(){
				var gr = jQuery("#list1").jqGrid('getGridParam','selrow');
				if( gr != null )
			  	jQuery("#list1").jqGrid('editGridRow',gr,{
			  		editCaption:"更改乡镇街道工作人员信息",
			  		bSubmit:"保存",bCancel:"取消",modal: true,
			  		closeAfterEdit:true,
			  		viewPagerButtons:false, 
			  		reloadAfterSubmit:true,
			  		beforeSubmit:checkValue,
			  		afterSubmit : function(r, postdata) {
			  					var data = eval('(' + r.responseText + ')');
			  					switch (data.code) {
			  						case 0: return [true, data.message]; break;
			  						default: return [false, data.message];
			  					}
			  		}
			  	});
				else
					showTips("请选择要更改的工作人员");
			}
		})
		.jqGrid('navButtonAdd','#gridpager1',{
   		caption:"删除", 
   		buttonicon:"ui-icon-close", 
   		onClickButton: function(){
				var gr = jQuery("#list1").jqGrid('getGridParam','selrow');
				if( gr != null )
			  	jQuery("#list1").jqGrid('delGridRow', gr, {
			  		caption:"确定要删除这个乡镇街道工作人员吗?", 
			  		msg:"确定要删除这个乡镇街道工作人员？",
			  		bSubmit:"删除",bCancel:"取消",modal: true,
			  		closeAfterEdit:true, 
			  		reloadAfterSubmit:true,
			  		beforeSubmit:checkValueForDel,
			  		afterSubmit : function(r, postdata) {
			  					var data = eval('(' + r.responseText + ')');
			  					switch (data.code) {
			  						case 0: return [true, data.message]; break;
			  						default: return [false, data.message];
			  					}
			  		}
			  	});
				else
					showTips("请选择要删除的工作人员");
			}
		});
}

function setGrid() {
	jQuery("#list1").jqGrid({ 
			url:'main?action=10',
			datatype: "json",
			hidegrid: "false",
			colNames:['用户ID','姓名','密码','行政区','乡镇街道','乡镇街道'], 
			colModel:[
					{name:'uid', width:200,sortable:false,align:'right',editable:true,editoptions:{size:8,maxlength:6},editrules:{required:true}}, 
					{name:'uname', width:260, sortable:false,align:'right',editable:true,editoptions:{size:8,maxlength:8},editrules:{required:true}}, 
					{name:'upass', width:190, sortable:false,align:'right',editable: true, edittype:"password",editoptions:{size:8,maxlength:6},editrules:{edithidden:true,required:true},hidden:true},
					{name:'district',width:280, sortable:false,align:'right', formatter:'select', editoptions:{value:"0:市残联;1:市辖区;2:桥东区;3:桥西区;4:高新区;5:宣化区;6:下花园区"}},
					{name:'sid', width:240, sortable:false,align:'right',hidden:true,editable:true,editrules:{edithidden:true},edittype:"select",editoptions:{dataUrl:'base?action=11'}},
					{name:'street', width:280, sortable:false,align:'right',formatter:setStreet}
			], 
			viewrecords: true,
			rowNum:100,
			pager: '#gridpager1',
			editurl:'main?action=10',
			caption:"残联办公人员管理",
			height: 380,
			gridComplete: function() {
				udistrict = jQuery("#list1").jqGrid('getGridParam', 'userData')["udistrict"];
				usid = jQuery("#list1").jqGrid('getGridParam', 'userData')["usid"];
				setButton();
			}
  })
}; 
	
	$(document).ready(function(){
		initStreet();
		setGrid();
	});
</script>

<body style="background-color:#d9f1cc;">
				<div id="RightPane">
					<div class="innertube">
					<table id="list1"></table>
					<div id="gridpager1"></div>
					</div>
				</div>
</body>
